package com.stu.covid.business.controller;

import com.stu.covid.business.entity.Student;
import com.stu.covid.business.entity.Teacher;
import com.stu.covid.business.service.StudentService;
import com.stu.covid.business.service.TeacherService;
import com.stu.covid.business.utils.Result;
import com.stu.covid.business.utils.SystemUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@Slf4j
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @GetMapping("/to-teacher-list")
    public String toTeacherList() {
        log.info("当前登录人:{}", SystemUtils.getLoginName());
        return "teacher_list";
    }

    @GetMapping("/to-teacher-add")
    public String toTeacherAdd() {
        return "teacher_add";
    }

    @RequestMapping("/teacher-list")
    @ResponseBody
    public Result<Teacher> teacherList(Teacher teacher) {
        return teacherService.teacherList(teacher);
    }

    @RequestMapping("/teacher-add")
    public String teacherAdd(Teacher teacher) {
        teacherService.teacherAdd(teacher);
        return "redirect:to-teacher-list";
    }

    @RequestMapping("/teacher-update")
    public String teacherUpdate(Teacher teacher) {
        teacherService.teacherUpdate(teacher);
        return "redirect:to-teacher-list";
    }

    @RequestMapping("/teacher-del")
    public String teacherDel(Teacher teacher) {
        teacherService.teacherDel(teacher.getId());
        return "redirect:to-teacher-list";
    }
}
